package com.koko.service.impl;

import com.koko.game.dto.GamePriceDTO;
import com.koko.game.entity.GamePrice;
import com.koko.mapper.GamePriceMapper;
import com.koko.service.GamePriceService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class GamePriceServiceImpl implements GamePriceService {
    @Autowired
    private GamePriceMapper gamePriceMapper;
    @Override
    public GamePrice getByGameId(Long gameId) {
        return gamePriceMapper.getByGameId(gameId);
    }

    @Override
    public void save(GamePrice gamePrice) {
        BigDecimal originPrice = gamePrice.getOriginPrice();
        gamePrice.setCurrentPrice(originPrice);
        gamePriceMapper.insert(gamePrice);
    }

    @Override
    public void deleteByGameId(Long gameId) {
        gamePriceMapper.deleteByGameId(gameId);
    }

    @Override
    public void update(GamePriceDTO gamePriceDTO) {
        GamePrice gamePrice = new GamePrice();
        BeanUtils.copyProperties(gamePriceDTO, gamePrice);
        gamePriceMapper.updateByGameId(gamePrice);
    }
}
